/*
	快速排序:
	把数组根据第一个元素(或任意一个元素)分为两部分,左边的比基准值小,右边的比基准值大


 */

function quick_sort(array, start, end) {
    if (!array) {
        return
    }
    if (start >= end) {
        return;
    }
    // var mid = Math.floor((start + end) / 2);
    var mid_val = array[start];
    var low = start;
    var hight = end;
    while (low < hight) {
        while (low < hight && array[hight] >= mid_val) {
            hight--;
        }
        array[low] = array[hight]

        while (low < hight && array[low] < mid_val) {
            low++;
        }
        array[hight] = array[low];
    }
    // 此时跳出循环,hight与low相等
    array[low] = mid_val;
    // 递归循环 左右两侧的数组
    quick_sort(array, start, low - 1);
    quick_sort(array, low + 1, end)
}





var arr = [32, 42, 1, 89, 23, 154, 79, 81, 66, 7];
console.log(' quick sort:');
quick_sort(arr, 0, arr.length - 1);
console.log(arr);